let mixin = {
  props: {

  },
  mounted() {

  },
  data() {
    return {
      nengxiaods: [],
    }
  },
  watch: {
    '$store.state.daping.efficiency.g_data_arr': {
      handler: function (n, o) {
        let _this = this
        //判断geojson是否加载完毕

        if (this.ds.length == 0) {
          setTimeout(() => {

            var entities = {}
            for (
              let index = 0;
              index < _this._viewer.dataSources.length;
              index++
            ) {
              if (_this.ds[0] == _this._viewer.dataSources.get(index)._name) {
                entities = _this._viewer.dataSources.get(index).entities.values
              }
            }
            for (var o = 0; o < entities.length; o++) {
              var entity = entities[o];
              if (entity.polygon != undefined) {
                let rescolor = _this.getefficcolor(n, entity.id, _this.$store.state.daping.efficiency.type, _this.$store.state.daping.efficiency.colorvalmap, _this.$store.state.daping.efficiency.colors)
                entity.polygon.stroke = Cesium.Color.fromCssColorString(rescolor);
                entity.polygon.material = Cesium.Color.fromCssColorString(rescolor);
                entity.polygon.strokeWidth = 5;

              }
            }
          }, 300);
        } else {

          var entities = {}
          for (
            let index = 0;
            index < this._viewer.dataSources.length;
            index++
          ) {
            if (this.ds[0] == this._viewer.dataSources.get(index)._name) {
              entities = this._viewer.dataSources.get(index).entities.values
            }
          }

          for (var o = 0; o < entities.length; o++) {
            var entity = entities[o];
            if (entity.polygon != undefined) {
              let rescolor = this.getefficcolor(n, entity.id, this.$store.state.daping.efficiency.type, this.$store.state.daping.efficiency.colorvalmap, this.$store.state.daping.efficiency.colors)

              entity.polygon.material = Cesium.Color.fromCssColorString(rescolor);
              entity.polygon.outline = false;

              let scal = 1

              switch (_this.$store.state.daping.efficiency.type) {
                case 'm_001t':
                case 'm_002t':
                case 'm_004t_1':
                case 'm_019t_1':
                  scal = 1
                  break;
                case 'm_003p':
                  scal = 1
                  break;
                case 'm_001p':
                  scal = 1
                  break;
                case 'm_003qc':
                  scal = 1
                  break;

                default:
                  break;
              }

              //注意这里..开始
              var polyPositions = entity.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
              var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center;
              polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
              entity.position = polyCenter;

              if (n[Number(entity.id)] && n[Number(entity.id)][_this.$store.state.daping.efficiency.type]) {

                let resheight = Math.floor(n[Number(entity.id)][_this.$store.state.daping.efficiency.type] * scal)

                entity.polygon.extrudedHeight = resheight

                var ellipsoid = _this._viewer.scene.globe.ellipsoid;
                let aaa = Cesium.Cartographic.fromCartesian(entity.position._value)
                aaa.height = resheight
                var cartesian3 = ellipsoid.cartographicToCartesian(aaa);
                entity.position = cartesian3

                entity.label = {
                  text: Math.floor(n[Number(entity.id)][_this.$store.state.daping.efficiency.type]) + "",
                  color: Cesium.Color.fromCssColorString('#55DD2F'),
                  font: 'normal 32px MicroSoft YaHei',
                  showBackground: false,
                  scale: 0.5,
                  horizontalOrigin: Cesium.HorizontalOrigin.LEFT_CLICK,
                  verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                  distanceDisplayCondition: new Cesium.DistanceDisplayCondition(10.0, 20000.0),
                  disableDepthTestDistance: 100.0,
                  // translucencyByDistance: 100,
                  // heightReference: 100,
                }
              }
            }
          }
        }
      }
    }
  },

  methods: {
    nengxiao() {
      let _this = this;
      var viewer = this._earth.czm.viewer;
      let geos = ["efficiency.json"];
      geos.map(item => {
        var promise = Cesium.GeoJsonDataSource.load("/geojson/" + item);
        promise.then(function (dataSource) {
          viewer.dataSources.add(dataSource);
          _this.ds.push(dataSource._name)
        });
      });
    }
  }
}

export default mixin